#!/bin/bash

readarray -t disks < <(lsblk -o NAME,SIZE,TYPE,MOUNTPOINT | grep 'disk')

echo "{"
disk_total=$(lsblk -o NAME,SIZE,TYPE,MOUNTPOINT | grep disk | awk '{sum += $2} END {print sum}')
echo "Total: $disk_total"
# 遍历数组中的每个元素
for disk in "${disks[@]}"; do
    # 使用IFS分割每个元素，并将它们存储在变量中
    name=$(echo "$disk" | awk '{print $1}')
    size=$(echo "$disk" | awk '{print $2}')
    type=$(echo "$disk" | awk '{print $3}')
    mountpoint=$(echo "$disk" | awk '{print $4}')

    # 输出提取的字段
    echo "{"
    echo "NAME: $name"
    echo "SIZE: $size"
    echo "TYPE: $type"
    echo "MOUNTPOINT: $mountpoint"
    echo "},"

    # 在这里可以进一步处理每个磁盘的信息，例如根据类型进行条件判断或执行其他操作
done
echo "}"